<template>
  <div
    class="message"
    v-if="isShow"
    :style="{
      backgroundColor: type === 'error' ? 'red' : 'green',
    }"
  >
    <div>
      <p>
        类型：{{ type }}<br />
        消息：{{ message }}
      </p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 消息提示类型
      type: "error",
      // 消息提示内容
      message: "这是提示消息!!",
      // 是否显示
      isShow: false,
    };
  },
  methods: {
    show() {
      this.isShow = true;
      console.log(this.type + ":" + this.message);
    },
    hide() {
      this.isShow = false;
      console.log(this.type + ":" + this.message);
    },
  },
};
</script>

<style lang="stylus" scoped>
.message {
  position: absolute;
  background: rgb(50, 100, 50);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 150px;
  height: 50px;
  font-size: 10px;
  text-align: center;
  line-height: 10px;
  color: white;
  & > {
    margin: 0px;
  }
}
</style>
